package com.cloud.logger.zchain.zchainserver.kafka;

import com.cloud.logger.zchain.core.common.util.DateUtil;
import com.cloud.logger.zchain.zchainserver.entity.AngelaLogger;
import com.cloud.logger.zchain.zchainserver.entity.AngelaLoggerProject;
import com.cloud.logger.zchain.zchainserver.entity.AngelaLoggerProjectNode;
import com.cloud.logger.zchain.zchainserver.entity.propertyenum.SwitchEnum;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaEntityRepository;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaProjectNodeDetailRepository;
import com.cloud.logger.zchain.zchainserver.mongo.AngelaProjectNodeRepository;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mongodb.WriteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.core.query.Update.update;

/**
 * User: wcy
 * Date: 2017/11/1
 * Time: 9:40
 */
@Component
public class KafkaConsumer {


    @Autowired
    AngelaEntityRepository angelaEntityRepository;

    private Gson gson = new GsonBuilder().create();

    @KafkaListener(topics = "logger")
    public void logger(String content) {
        AngelaLogger m = gson.fromJson(content, AngelaLogger.class);
        m.setCreateTime(new Date());
        angelaEntityRepository.save(m);
    }

}